package com.learn.bridge;

import com.learn.bridge.bridge.ConcreteBridge;
import com.learn.bridge.implementor.ConcreteImplementorA;
import com.learn.bridge.implementor.ConcreteImplementorB;

/**
 * <p>项目名称: design-pattern </p>
 *
 * <p>文件名称: App </p>
 *
 * Composition over inheritance. The Bridge pattern can also be thought of as two layers of abstraction.
 * With Bridge, you can decouple an abstraction from its implementation so that the two can vary independently.
 * <p>
 * In Bridge pattern both abstraction ({@link Bridge}) and implementation (
 * {@link Implementor}) have their own class hierarchies. The interface of the implementations
 * can be changed without affecting the clients.
 * <p>
 * In this example we have two class hierarchies. One of weapons and another one of enchantments. We can easily
 * combine any weapon with any enchantment using composition instead of creating deep class hierarchy.
 */
public class App {

    public static void main(String[] args) {
        ConcreteBridge bridge = new ConcreteBridge(new ConcreteImplementorA());
        bridge.operation();

        ConcreteBridge bridge2 = new ConcreteBridge(new ConcreteImplementorB());
        bridge2.operation();
    }
}
